using DAO;
using Easislides.Properties;
using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
using System.Xml;
namespace Easislides
{
	public class FrmImport : Form
	{
		private IContainer components = null;
		private GroupBox groupBox1;
		private Panel panelLinkTitle2Lookup;
		private ToolStrip toolStrip2;
		private ToolStripButton LocationBtn;
		private Label tbImportFrom;
		private ProgressBar ProgressBar1;
		private CheckedListBox ImportFolderList;
		private GroupBox groupBox2;
		private GroupBox groupBox3;
		private GroupBox groupBox4;
		private Button BtnCancel;
		private Button BtnOK;
		private ListView SongFolder;
		private ColumnHeader columnHeader1;
		private RadioButton OptImport2;
		private RadioButton OptImport1;
		private RadioButton OptImport0;
		private ListView SongsList;
		private ColumnHeader columnHeader2;
		private ColumnHeader columnHeader3;
		private ColumnHeader columnHeader4;
		private OpenFileDialog OpenFileDialog1;
		private string InSeq;
		private string InTxt;
		private string OneSong;
		private string InFileName;
		private string MsgText;
		private int InTotal;
		private string SongNumber;
		private string MusicNotations;
		private string SongTiming;
		private string SongCapo;
		private string SongKey;
		private string SongHeader;
		private string tempSequence;
		private string SongSequence;
		private string UserReference;
		private string BookReference;
		private string SongCopyright;
		private string SongWriterInfo;
		private string SongLyrics;
		private string SongTitle2;
		private string SongTitle;
		private string Lic_Admin2;
		private string Lic_Admin1;
		private string TextImportFormat;
		private string CJK_WCount;
		private string CJK_SCount;
		private int CurSongID;
		private int SongsNew;
		private int SongsUpdated;
		private int DataProcessedSoFar;
		private int FileDataSize;
		private int ImportFileSize;
		private int Filelength;
		private int InFolderNo;
		private string[] sArray;
		private string[] EsfFolderNames = new string[41];
		private string esf1SongTitle = "[#";
		private string esf1SongTitle2 = "##";
		private string esf1SongFolder = "#f";
		private string esf1SongCopyright = "#c";
		private string esf1BookReference = "#r";
		private string esf1UserReference = "#u";
		private string esf1SongWriterInfo = "#w";
		private string esf1SongKey = "#k";
		private string esf1SongTiming = "#t";
		private string esf1SongCapo = "#0";
		private string esf1SongNumber = "#n";
		private string esf1SongAdmin1 = "#a";
		private string esf1SongAdmin2 = "#b";
		private string esf1Sequence = "#@";
		private string esf1SongFormat = "#q";
		private string esfImportFieldSeparator;
		private string esfImportFormatTitle;
		private string esfSongTitle;
		private string esfSongTitle2;
		private string esfSongFolder;
		private string esfBookReference;
		private string esfUserReference;
		private string esfSongCopyright;
		private string esfSongWriterInfo;
		private string esfSongKey;
		private string esfSongTiming;
		private string esfSongCapo;
		private string esfSongNumber;
		private string esfSongAdmin1;
		private string esfSongAdmin2;
		private string esfSequence;
		private string esfSongFormat;
		private int FolderLookupSongsCount = 0;
		private gf.SongSettings ImportItem = new gf.SongSettings();
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.panelLinkTitle2Lookup = new System.Windows.Forms.Panel();
            this.toolStrip2 = new System.Windows.Forms.ToolStrip();
            this.LocationBtn = new System.Windows.Forms.ToolStripButton();
            this.tbImportFrom = new System.Windows.Forms.Label();
            this.ProgressBar1 = new System.Windows.Forms.ProgressBar();
            this.ImportFolderList = new System.Windows.Forms.CheckedListBox();
            this.groupBox2 = new System.Windows.Forms.GroupBox();
            this.groupBox3 = new System.Windows.Forms.GroupBox();
            this.SongFolder = new System.Windows.Forms.ListView();
            this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.groupBox4 = new System.Windows.Forms.GroupBox();
            this.OptImport2 = new System.Windows.Forms.RadioButton();
            this.OptImport1 = new System.Windows.Forms.RadioButton();
            this.OptImport0 = new System.Windows.Forms.RadioButton();
            this.BtnCancel = new System.Windows.Forms.Button();
            this.BtnOK = new System.Windows.Forms.Button();
            this.SongsList = new System.Windows.Forms.ListView();
            this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.columnHeader4 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.OpenFileDialog1 = new System.Windows.Forms.OpenFileDialog();
            this.groupBox1.SuspendLayout();
            this.panelLinkTitle2Lookup.SuspendLayout();
            this.toolStrip2.SuspendLayout();
            this.groupBox2.SuspendLayout();
            this.groupBox3.SuspendLayout();
            this.groupBox4.SuspendLayout();
            this.SuspendLayout();
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.panelLinkTitle2Lookup);
            this.groupBox1.Controls.Add(this.tbImportFrom);
            this.groupBox1.Location = new System.Drawing.Point(12, 8);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(520, 49);
            this.groupBox1.TabIndex = 0;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "A - Import File:";
            // 
            // panelLinkTitle2Lookup
            // 
            this.panelLinkTitle2Lookup.Controls.Add(this.toolStrip2);
            this.panelLinkTitle2Lookup.Location = new System.Drawing.Point(492, 16);
            this.panelLinkTitle2Lookup.Name = "panelLinkTitle2Lookup";
            this.panelLinkTitle2Lookup.Size = new System.Drawing.Size(22, 22);
            this.panelLinkTitle2Lookup.TabIndex = 51;
            // 
            // toolStrip2
            // 
            this.toolStrip2.AutoSize = false;
            this.toolStrip2.CanOverflow = false;
            this.toolStrip2.Dock = System.Windows.Forms.DockStyle.None;
            this.toolStrip2.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;
            this.toolStrip2.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.LocationBtn});
            this.toolStrip2.LayoutStyle = System.Windows.Forms.ToolStripLayoutStyle.Flow;
            this.toolStrip2.Location = new System.Drawing.Point(0, 0);
            this.toolStrip2.Name = "toolStrip2";
            this.toolStrip2.RenderMode = System.Windows.Forms.ToolStripRenderMode.System;
            this.toolStrip2.Size = new System.Drawing.Size(25, 28);
            this.toolStrip2.TabIndex = 5;
            // 
            // LocationBtn
            // 
            this.LocationBtn.AutoSize = false;
            this.LocationBtn.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.LocationBtn.Image = global::Properties.Resources.open;
            this.LocationBtn.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.LocationBtn.Name = "LocationBtn";
            this.LocationBtn.Size = new System.Drawing.Size(22, 22);
            this.LocationBtn.Tag = "";
            this.LocationBtn.ToolTipText = "Export file name";
            this.LocationBtn.Click += new System.EventHandler(this.LocationBtn_Click);
            // 
            // tbImportFrom
            // 
            this.tbImportFrom.BackColor = System.Drawing.SystemColors.Control;
            this.tbImportFrom.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.tbImportFrom.Location = new System.Drawing.Point(9, 16);
            this.tbImportFrom.Name = "tbImportFrom";
            this.tbImportFrom.Size = new System.Drawing.Size(480, 22);
            this.tbImportFrom.TabIndex = 50;
            this.tbImportFrom.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // ProgressBar1
            // 
            this.ProgressBar1.Location = new System.Drawing.Point(12, 308);
            this.ProgressBar1.Name = "ProgressBar1";
            this.ProgressBar1.Size = new System.Drawing.Size(520, 21);
            this.ProgressBar1.Step = 1;
            this.ProgressBar1.Style = System.Windows.Forms.ProgressBarStyle.Continuous;
            this.ProgressBar1.TabIndex = 5;
            // 
            // ImportFolderList
            // 
            this.ImportFolderList.CheckOnClick = true;
            this.ImportFolderList.FormattingEnabled = true;
            this.ImportFolderList.Location = new System.Drawing.Point(9, 17);
            this.ImportFolderList.Name = "ImportFolderList";
            this.ImportFolderList.Size = new System.Drawing.Size(143, 79);
            this.ImportFolderList.TabIndex = 50;
            // 
            // groupBox2
            // 
            this.groupBox2.Controls.Add(this.ImportFolderList);
            this.groupBox2.Location = new System.Drawing.Point(12, 63);
            this.groupBox2.Name = "groupBox2";
            this.groupBox2.Size = new System.Drawing.Size(160, 102);
            this.groupBox2.TabIndex = 1;
            this.groupBox2.TabStop = false;
            this.groupBox2.Text = "B - Import File Folders (if any)";
            // 
            // groupBox3
            // 
            this.groupBox3.Controls.Add(this.SongFolder);
            this.groupBox3.Location = new System.Drawing.Point(178, 63);
            this.groupBox3.Name = "groupBox3";
            this.groupBox3.Size = new System.Drawing.Size(180, 102);
            this.groupBox3.TabIndex = 2;
            this.groupBox3.TabStop = false;
            this.groupBox3.Text = "C - Select Folder to import into";
            // 
            // SongFolder
            // 
            this.SongFolder.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
            this.columnHeader1});
            this.SongFolder.FullRowSelect = true;
            this.SongFolder.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
            this.SongFolder.HideSelection = false;
            this.SongFolder.Location = new System.Drawing.Point(6, 16);
            this.SongFolder.MultiSelect = false;
            this.SongFolder.Name = "SongFolder";
            this.SongFolder.ShowGroups = false;
            this.SongFolder.ShowItemToolTips = true;
            this.SongFolder.Size = new System.Drawing.Size(168, 80);
            this.SongFolder.TabIndex = 56;
            this.SongFolder.UseCompatibleStateImageBehavior = false;
            this.SongFolder.View = System.Windows.Forms.View.Details;
            // 
            // columnHeader1
            // 
            this.columnHeader1.Text = "";
            this.columnHeader1.Width = 140;
            // 
            // groupBox4
            // 
            this.groupBox4.Controls.Add(this.OptImport2);
            this.groupBox4.Controls.Add(this.OptImport1);
            this.groupBox4.Controls.Add(this.OptImport0);
            this.groupBox4.Location = new System.Drawing.Point(364, 63);
            this.groupBox4.Name = "groupBox4";
            this.groupBox4.Size = new System.Drawing.Size(168, 102);
            this.groupBox4.TabIndex = 3;
            this.groupBox4.TabStop = false;
            this.groupBox4.Text = "D - If Title exists in EasiSlides";
            // 
            // OptImport2
            // 
            this.OptImport2.Location = new System.Drawing.Point(6, 66);
            this.OptImport2.Name = "OptImport2";
            this.OptImport2.Size = new System.Drawing.Size(150, 30);
            this.OptImport2.TabIndex = 2;
            this.OptImport2.Text = "IMPORT and REPLACE existing item.";
            // 
            // OptImport1
            // 
            this.OptImport1.Location = new System.Drawing.Point(6, 35);
            this.OptImport1.Name = "OptImport1";
            this.OptImport1.Size = new System.Drawing.Size(150, 33);
            this.OptImport1.TabIndex = 1;
            this.OptImport1.Text = "IMPORT but also KEEP existing item";
            // 
            // OptImport0
            // 
            this.OptImport0.Checked = true;
            this.OptImport0.Location = new System.Drawing.Point(6, 12);
            this.OptImport0.Name = "OptImport0";
            this.OptImport0.Size = new System.Drawing.Size(150, 28);
            this.OptImport0.TabIndex = 0;
            this.OptImport0.TabStop = true;
            this.OptImport0.Text = "DO NOT Import the item";
            // 
            // BtnCancel
            // 
            this.BtnCancel.Location = new System.Drawing.Point(452, 338);
            this.BtnCancel.Name = "BtnCancel";
            this.BtnCancel.Size = new System.Drawing.Size(80, 24);
            this.BtnCancel.TabIndex = 7;
            this.BtnCancel.Text = "Close";
            this.BtnCancel.Click += new System.EventHandler(this.BtnCancel_Click);
            // 
            // BtnOK
            // 
            this.BtnOK.Location = new System.Drawing.Point(356, 338);
            this.BtnOK.Name = "BtnOK";
            this.BtnOK.Size = new System.Drawing.Size(80, 24);
            this.BtnOK.TabIndex = 6;
            this.BtnOK.Text = "Import";
            this.BtnOK.Click += new System.EventHandler(this.BtnOK_Click);
            // 
            // SongsList
            // 
            this.SongsList.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
            this.columnHeader2,
            this.columnHeader3,
            this.columnHeader4});
            this.SongsList.FullRowSelect = true;
            this.SongsList.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
            this.SongsList.HideSelection = false;
            this.SongsList.LabelWrap = false;
            this.SongsList.Location = new System.Drawing.Point(12, 170);
            this.SongsList.Name = "SongsList";
            this.SongsList.ShowItemToolTips = true;
            this.SongsList.Size = new System.Drawing.Size(520, 137);
            this.SongsList.TabIndex = 4;
            this.SongsList.UseCompatibleStateImageBehavior = false;
            this.SongsList.View = System.Windows.Forms.View.Details;
            // 
            // columnHeader2
            // 
            this.columnHeader2.Text = "Item";
            this.columnHeader2.Width = 54;
            // 
            // columnHeader3
            // 
            this.columnHeader3.Text = "Title";
            this.columnHeader3.Width = 229;
            // 
            // columnHeader4
            // 
            this.columnHeader4.Text = "Status";
            this.columnHeader4.Width = 209;
            // 
            // OpenFileDialog1
            // 
            this.OpenFileDialog1.FileName = "openFileDialog1";
            // 
            // FrmImport
            // 
            this.ClientSize = new System.Drawing.Size(542, 374);
            this.Controls.Add(this.SongsList);
            this.Controls.Add(this.BtnCancel);
            this.Controls.Add(this.BtnOK);
            this.Controls.Add(this.groupBox4);
            this.Controls.Add(this.groupBox3);
            this.Controls.Add(this.groupBox2);
            this.Controls.Add(this.ProgressBar1);
            this.Controls.Add(this.groupBox1);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.KeyPreview = true;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "FrmImport";
            this.ShowIcon = false;
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Import";
            this.Load += new System.EventHandler(this.FrmImport_Load);
            this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.FrmImport_KeyUp);
            this.groupBox1.ResumeLayout(false);
            this.panelLinkTitle2Lookup.ResumeLayout(false);
            this.toolStrip2.ResumeLayout(false);
            this.toolStrip2.PerformLayout();
            this.groupBox2.ResumeLayout(false);
            this.groupBox3.ResumeLayout(false);
            this.groupBox4.ResumeLayout(false);
            this.ResumeLayout(false);

		}
		public FrmImport()
		{
			this.InitializeComponent();
		}
		private void FrmImport_Load(object sender, EventArgs e)
		{
			this.ProgressBar1.Visible = false;
			this.OptImport1.Checked = true;
			this.BuildFolderList();
			this.ImportItem.Initialise();
		}
		private void BuildFolderList()
		{
			this.SongFolder.Items.Clear();
			for (int i = 1; i < 41; i++)
			{
				if (gf.FolderUse[i] > 0)
				{
					this.SongFolder.Items.Add(gf.FolderName[i]);
				}
			}
		}
		private void BuildImportFolderList()
		{
			string text = gf.Trim(this.tbImportFrom.Text);
			if (File.Exists(text))
			{
				this.ImportFolderList.Items.Clear();
				string text2 = gf.Right(text, 4).ToLower();
				if (text2 != null)
				{
					if (!(text2 == ".esf"))
					{
						if (!(text2 == ".est"))
						{
							if (!(text2 == ".esn"))
							{
								if (text2 == ".xml")
								{
									this.BuildImportFolderList_ESXML(text);
								}
							}
							else
							{
								this.BuildImportFolderList_ESTextFile(text);
							}
						}
						else
						{
							this.BuildImportFolderList_ESTextFile(text);
						}
					}
					else
					{
						this.BuildImportFolderList_Database(text);
					}
				}
			}
		}
		private void BuildImportFolderList_Database(string ImportFileName)
		{
			this.ImportFolderList.Items.Clear();
			Database daoDb = gf.GetDaoDb(gf.ConnectStringDef + ImportFileName);
			for (int i = 0; i < 41; i++)
			{
				this.EsfFolderNames[i] = "";
			}
			bool flag = false;
			foreach (Field field in daoDb.TableDefs["Song"].Fields)
			{
				if (field.Name == "USER_REFERENCE")
				{
					flag = true;
				}
			}
			string fullSearchString = "select * from Folder where FolderNo > 0 order by folderno ";
			Recordset recordSet = gf.GetRecordSet(daoDb, fullSearchString);
			if (recordSet != null && !recordSet.EOF)
			{
				recordSet.MoveFirst();
				while (!recordSet.EOF)
				{
					this.EsfFolderNames[gf.GetDataInt(recordSet, "FolderNo")] = gf.GetDataString(recordSet, "name");
					if (flag)
					{
						this.ImportFolderList.Items.Add(gf.GetDataString(recordSet, "name"));
					}
					else
					{
						if (gf.GetDataInt(recordSet, "FolderNo") == 1)
						{
							this.ImportFolderList.Items.Add(gf.GetDataString(recordSet, "name"));
						}
					}
					recordSet.MoveNext();
				}
			}
		}
		private void BuildImportFolderList_ESTextFile(string ImportFileName)
		{
			this.ImportFolderList.Items.Clear();
			this.FolderLookupSongsCount = 0;
			string text = "";
			if (gf.LoadFileContents(ImportFileName, ref text))
			{
				this.TextImportFormat = gf.Left(text, 8).ToLower();
				if (this.TextImportFormat == "[esf1.0]")
				{
					this.esfSongFolder = this.esf1SongFolder;
					this.esfImportFieldSeparator = "#";
					this.esfImportFormatTitle = "[" + this.esfImportFieldSeparator;
				}
				else
				{
					if (!(this.TextImportFormat == "[est3.1]"))
					{
						goto IL_2CA;
					}
					this.esfSongFolder = ">f";
					this.esfImportFieldSeparator = '>'.ToString();
					this.esfImportFormatTitle = "[>";
				}
				text = gf.Right(text, text.Length - 8);
				text = text.Replace(this.esfImportFormatTitle, Convert.ToString('\u0001'));
				string[] array = text.Split(new char[]
				{
					'\u0001'
				});
				ListViewItem listViewItem = new ListViewItem();
				if (array != null && array.GetUpperBound(0) >= 0)
				{
					for (int i = 0; i <= array.GetUpperBound(0); i++)
					{
						int num = array[i].IndexOf("]");
						string text2 = gf.Left(array[i], (num > 0) ? num : 0);
						if (text2.Length > 0)
						{
							int num2 = text2.IndexOf(this.esfSongFolder);
							string text3;
							if (num2 >= 0 & text2.Length > num2)
							{
								int num3 = text2.IndexOf(this.esfImportFieldSeparator, num2 + 1);
								if (num3 > 0)
								{
									text3 = gf.Mid(text2, num2 + this.esfSongFolder.Length, num3 - (num2 + this.esfSongFolder.Length));
								}
								else
								{
									text3 = gf.Mid(text2, num2 + this.esfSongFolder.Length);
								}
							}
							else
							{
								text3 = "Default Folder";
							}
							this.FolderLookupSongsCount++;
							bool flag = false;
							for (int j = 0; j < this.ImportFolderList.Items.Count; j++)
							{
								if (this.ImportFolderList.Items[j].ToString() == text3)
								{
									flag = true;
								}
							}
							if (!flag)
							{
								this.ImportFolderList.Items.Add(text3);
							}
						}
					}
				}
				return;
			}
			IL_2CA:
			MessageBox.Show("There was an error reading the Import File - the file might not be a valid EasiSlides File");
		}
		private void BuildImportFolderList_ESXML(string ImportFileName)
		{
			this.FolderLookupSongsCount = 0;
			this.ImportFolderList.Items.Clear();
			ListViewItem listViewItem = new ListViewItem();
			try
			{
				XmlTextReader xmlTextReader = new XmlTextReader(ImportFileName);
				bool flag = gf.ValidateEasiSlidesXML(ref xmlTextReader);
				if (flag)
				{
					while (gf.ExtractEasiSlidesXMLItem(ref xmlTextReader, ref this.ImportItem))
					{
						string text = (this.ImportItem.FolderName == "") ? "Default Folder" : this.ImportItem.FolderName;
						this.FolderLookupSongsCount++;
						bool flag2 = false;
						for (int i = 0; i < this.ImportFolderList.Items.Count; i++)
						{
							if (this.ImportFolderList.Items[i].ToString() == text)
							{
								flag2 = true;
							}
						}
						if (!flag2)
						{
							this.ImportFolderList.Items.Add(text);
						}
					}
				}
				if (xmlTextReader != null)
				{
					xmlTextReader.Close();
				}
			}
			catch
			{
			}
		}
		private void LocationBtn_Click(object sender, EventArgs e)
		{
			this.OpenFileDialog1.Filter = "EasiSlides/XML Files (*.esf,*.esn,*.xml)|*.esf;*.est;*.esn;*.xml|Access Database (*.mdb)|*.mdb";
			this.OpenFileDialog1.InitialDirectory = gf.ImportFromDir;
			this.OpenFileDialog1.AddExtension = true;
			this.OpenFileDialog1.DefaultExt = "*.xml";
			this.OpenFileDialog1.FileName = "";
			if (this.OpenFileDialog1.ShowDialog() == DialogResult.OK)
			{
				this.tbImportFrom.Text = this.OpenFileDialog1.FileName;
				gf.ImportFromDir = Path.GetDirectoryName(this.tbImportFrom.Text) + "\\";
				this.BuildImportFolderList();
			}
		}
		private void BtnOK_Click(object sender, EventArgs e)
		{
			this.Start_Import();
		}
		private void Start_Import()
		{
			string text = gf.Trim(this.tbImportFrom.Text);
			if (text == "")
			{
				MessageBox.Show("Please specify an import file (A).");
			}
			else
			{
				if (!File.Exists(text))
				{
					MessageBox.Show("The selected import file doesn't exist! Please re-select the import file (A).");
				}
				else
				{
					if (this.ImportFolderList.Items.Count > 0 & this.ImportFolderList.CheckedItems.Count < 1)
					{
						MessageBox.Show("Please select Folder(s) from the list of Import File Folders (B).");
					}
					else
					{
						if (this.SongFolder.SelectedItems.Count < 1)
						{
							MessageBox.Show("Please select a Folder to Import your items into (C).");
						}
						else
						{
							if (gf.Right(text, 4).ToLower() == ".esf")
							{
								this.Import_DatabaseFormat(text);
							}
							else
							{
								if (gf.Right(text, 4).ToLower() == ".est")
								{
									this.Import_TextFormat(text);
								}
								else
								{
									if (gf.Right(text, 4).ToLower() == ".esn")
									{
										this.Import_TextFormat(text);
									}
									else
									{
										if (gf.Right(text, 4).ToLower() == ".xml")
										{
											this.Import_XMLFormat(text);
										}
										else
										{
											if (gf.Right(text, 4).ToLower() == ".mdb")
											{
												this.AccessHelper(text);
											}
											else
											{
												MessageBox.Show("Sorry - The Import File you have selected in (A) does not have a valid EasiSlides file extension.");
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
		private void Import_DatabaseFormat(string ImportFileName)
		{
			int num = 0;
			ListViewItem listViewItem = new ListViewItem();
			string text = "";
			this.SongsUpdated = 0;
			this.SongsNew = 0;
			this.Cursor = Cursors.WaitCursor;
			this.SongsList.Items.Clear();
			this.ProgressBar1.Visible = true;
			this.ProgressBar1.Value = 0;
			if (this.ImportFolderList.CheckedItems.Count > 0)
			{
				for (int i = 0; i < this.ImportFolderList.CheckedItems.Count; i++)
				{
					if (text == "")
					{
						text = " where (FolderNo=" + this.GetImportFolderNumber(this.ImportFolderList.CheckedItems[i].ToString());
					}
					else
					{
						text = text + " or FolderNo=" + this.GetImportFolderNumber(this.ImportFolderList.CheckedItems[i].ToString());
					}
				}
				text += ") ";
			}
			int num2 = 0;
			Recordset recordSet = gf.GetRecordSet(gf.ConnectStringDef + ImportFileName, "select * from SONG " + text);
			if (recordSet != null && !recordSet.EOF)
			{
				recordSet.MoveFirst();
				while (!recordSet.EOF)
				{
					num2++;
					recordSet.MoveNext();
				}
				recordSet.MoveFirst();
				listViewItem = this.SongsList.Items.Add("Importing...");
				this.InFolderNo = gf.GetFolderNumber(this.SongFolder.SelectedItems[0].Text);
				Database daoDb = gf.GetDaoDb(gf.ConnectStringMainDB);
				Recordset recordset = null;
				while (!recordSet.EOF)
				{
					bool songRequired = false;
					num++;
					int num3 = num * 100 / num2;
					this.ProgressBar1.Value = ((num3 > 100) ? 100 : num3);
					base.Invalidate();
					this.ProgressBar1.Invalidate();
					if (gf.LoadDataIntoItem(ref this.ImportItem, recordSet))
					{
						listViewItem = this.SongsList.Items.Add(Convert.ToString(num));
						listViewItem.SubItems.Add(this.ImportItem.Title);
						string fullSearchString = string.Concat(new string[]
						{
							"select * from SONG where Folderno=",
							this.InFolderNo.ToString(),
							" and Title_1 = \"",
							this.ImportItem.Title,
							"\""
						});
						songRequired = true;
						this.ImportItem.FolderNo = this.InFolderNo;
						recordset = gf.GetRecordSet(daoDb, fullSearchString);
					}
					if (recordset != null && !recordset.EOF)
					{
						recordset.MoveFirst();
						this.CurSongID = gf.GetDataInt(recordset, "SongID");
						if (this.OptImport0.Checked)
						{
							songRequired = false;
						}
						else
						{
							if (this.OptImport1.Checked)
							{
								this.CurSongID = -1;
							}
						}
					}
					else
					{
						this.CurSongID = -1;
					}
					if (recordset != null)
					{
						recordset.Close();
					}
					this.SaveSong(songRequired, this.CurSongID, this.ImportItem, ref listViewItem, ref this.SongsNew, ref this.SongsUpdated);
					recordSet.MoveNext();
					this.SongsList.Items[this.SongsList.Items.Count - 1].EnsureVisible();
					this.SongsList.Update();
				}
				recordSet.Close();
				this.ProgressBar1.Value = 100;
				this.Show_Import_Result();
				if (recordset != null)
				{
				}
				if (recordSet != null)
				{
				}
				this.Cursor = Cursors.Default;
			}
			else
			{
				this.Cursor = Cursors.Default;
			}
		}
		private void Import_XMLFormat(string ImportFileName)
		{
			int num = 0;
			ListViewItem listViewItem = new ListViewItem();
			this.SongsUpdated = 0;
			this.SongsNew = 0;
			this.SongsList.Items.Clear();
			Database daoDb = gf.GetDaoDb(gf.ConnectStringMainDB);
			listViewItem = this.SongsList.Items.Add("");
			listViewItem.SubItems.Add("Starting Import...");
			int folderNumber = gf.GetFolderNumber(this.SongFolder.SelectedItems[0].Text);
			int num2 = 0;
			string text = "";
			for (int i = 0; i < this.ImportFolderList.CheckedItems.Count; i++)
			{
				text = text + this.ImportFolderList.CheckedItems[i].ToString() + ";";
			}
			try
			{
				XmlTextReader xmlTextReader = new XmlTextReader(ImportFileName);
				bool flag = gf.ValidateEasiSlidesXML(ref xmlTextReader);
				if (flag)
				{
					this.Cursor = Cursors.WaitCursor;
					this.ProgressBar1.Visible = true;
					this.ProgressBar1.Value = 0;
					if (this.FolderLookupSongsCount < 1)
					{
						this.FolderLookupSongsCount = 1;
					}
					while (gf.ExtractEasiSlidesXMLItem(ref xmlTextReader, ref this.ImportItem))
					{
						string str = (this.ImportItem.FolderName == "") ? "Default Folder" : this.ImportItem.FolderName;
						num++;
						int num3 = num * 100 / this.FolderLookupSongsCount;
						this.ProgressBar1.Value = ((num3 > 100) ? 100 : num3);
						base.Invalidate();
						this.ProgressBar1.Invalidate();
						if (text.IndexOf(str + ";") >= 0)
						{
							num2++;
							listViewItem = this.SongsList.Items.Add(num2.ToString());
							listViewItem.SubItems.Add(this.ImportItem.Title);
							string fullSearchString = string.Concat(new string[]
							{
								"select * from SONG where Folderno=",
								Convert.ToString(folderNumber),
								" and Title_1 = \"",
								this.ImportItem.Title,
								"\""
							});
							bool flag2 = true;
							Recordset recordSet = gf.GetRecordSet(daoDb, fullSearchString);
							if (recordSet != null && !recordSet.EOF)
							{
								recordSet.MoveFirst();
								this.CurSongID = gf.GetDataInt(recordSet, "SongID");
								if (this.OptImport0.Checked)
								{
									flag2 = false;
								}
								else
								{
									if (this.OptImport1.Checked)
									{
										this.CurSongID = -1;
									}
								}
							}
							else
							{
								this.CurSongID = -1;
							}
							if (recordSet != null)
							{
								recordSet.Close();
							}
							if (flag2)
							{
								if (this.ImportItem.Title != "")
								{
									this.ImportItem.CompleteLyrics = this.ImportItem.CompleteLyrics.TrimStart(new char[]
									{
										'\n',
										'\r'
									});
									this.ImportItem.CompleteLyrics = this.ImportItem.CompleteLyrics.Replace("\r\n", "\n");
									this.ImportItem.FolderNo = folderNumber;
									this.SaveSong(flag2, this.CurSongID, this.ImportItem, ref listViewItem, ref this.SongsNew, ref this.SongsUpdated);
								}
								else
								{
									listViewItem.SubItems.Add("Item has No Title - Not Imported");
								}
							}
							else
							{
								listViewItem.SubItems.Add("Song exists in Database - NOT Imported");
							}
						}
						this.SongsList.Items[this.SongsList.Items.Count - 1].EnsureVisible();
						this.SongsList.Update();
					}
					this.Cursor = Cursors.Default;
					this.ProgressBar1.Value = 100;
					this.Show_Import_Result();
				}
				else
				{
					MessageBox.Show("Selected XML File is not formatted correctly for EasiSlides use. Import NOT Done");
				}
				if (xmlTextReader != null)
				{
					xmlTextReader.Close();
				}
			}
			catch
			{
			}
			this.Cursor = Cursors.Default;
		}
		private void Show_Import_Result()
		{
			ListViewItem listViewItem = new ListViewItem();
			string text = "";
			string text2 = "";
			string text3 = "";
			if (this.SongsNew == 0 & this.SongsUpdated == 0)
			{
				text = "No Songs were imported. ";
			}
			else
			{
				if (this.SongsNew >= 1)
				{
					if (this.SongsNew == 1)
					{
						text2 = "Imported one new song. ";
					}
					else
					{
						text2 = "Imported " + Convert.ToString(this.SongsNew) + " new songs. ";
					}
				}
				if (this.SongsUpdated >= 1)
				{
					if (this.SongsUpdated == 1)
					{
						text3 = "Replaced one existing song. ";
					}
					else
					{
						text3 = "Replaced " + Convert.ToString(this.SongsUpdated) + " existing songs. ";
					}
				}
			}
			listViewItem = this.SongsList.Items.Add("");
			listViewItem.SubItems.Add("Completed.");
			listViewItem = this.SongsList.Items.Add("");
			listViewItem.SubItems.Add(text + text2 + text3);
			this.SongsList.Items.Add("");
			this.SongsList.Items[this.SongsList.Items.Count - 1].EnsureVisible();
			this.SongsList.Update();
			MessageBox.Show("Completed. " + text + text2 + text3);
			this.ProgressBar1.Visible = false;
			if (gf.Right(gf.Trim(this.tbImportFrom.Text), 4) == ".mdb")
			{
				this.tbImportFrom.Text = "";
			}
		}
		private string GetImportFolderNumber(string InFolderName)
		{
			string result;
			for (int i = 1; i < 41; i++)
			{
				if (this.EsfFolderNames[i] == InFolderName)
				{
					result = i.ToString();
					return result;
				}
			}
			result = "0";
			return result;
		}
		private void SaveSong(bool SongRequired, int InSongID, gf.SongSettings InItem, ref ListViewItem cItem, ref int SongsNew, ref int SongsUpdated)
		{
			if (SongRequired)
			{
				if (this.CurSongID < 1)
				{
					gf.InsertItemIntoDatabase(gf.ConnectStringMainDB, InItem);
					cItem.SubItems.Add("++ Imported as a New Item ++");
					SongsNew++;
				}
				else
				{
					gf.UpdateDatabaseItem(gf.ConnectStringMainDB, InItem, this.CurSongID);
					cItem.SubItems.Add("** Existing Item in Database Replaced **");
					SongsUpdated++;
				}
			}
			else
			{
				cItem.SubItems.Add("Not Imported");
			}
		}
		private void Import_TextFormat(string ImportFileName)
		{
			string text = "";
			if (gf.LoadFileContents(ImportFileName, ref text))
			{
				this.TextImportFormat = gf.Left(text, 8).ToLower();
				if (this.TextImportFormat == "[esf1.0]")
				{
					this.esfSongTitle = this.esf1SongTitle;
					this.esfSongTitle2 = this.esf1SongTitle2;
					this.esfSongNumber = this.esf1SongNumber;
					this.esfSongFolder = this.esf1SongFolder;
					this.esfBookReference = this.esf1BookReference;
					this.esfUserReference = this.esf1UserReference;
					this.esfSongCopyright = this.esf1SongCopyright;
					this.esfSongWriterInfo = this.esf1SongWriterInfo;
					this.esfSongKey = this.esf1SongKey;
					this.esfSongTiming = this.esf1SongTiming;
					this.esfSongCapo = this.esf1SongCapo;
					this.esfSongAdmin1 = this.esf1SongAdmin1;
					this.esfSongAdmin2 = this.esf1SongAdmin2;
					this.esfSequence = this.esf1Sequence;
					this.esfSongFormat = this.esf1SongFormat;
					this.esfImportFieldSeparator = "#";
					this.esfImportFormatTitle = "[" + this.esfImportFieldSeparator;
				}
				else
				{
					if (!(this.TextImportFormat == "[est3.1]"))
					{
						goto IL_7C3;
					}
					this.esfSongTitle = "[>";
					this.esfSongTitle2 = ">>";
					this.esfSongNumber = ">n";
					this.esfSongFolder = ">f";
					this.esfBookReference = ">r";
					this.esfUserReference = ">u";
					this.esfSongCopyright = ">c";
					this.esfSongWriterInfo = ">w";
					this.esfSongKey = ">k";
					this.esfSongTiming = ">t";
					this.esfSongCapo = ">0";
					this.esfSongAdmin1 = ">a";
					this.esfSongAdmin2 = ">b";
					this.esfSequence = ">@";
					this.esfSongFormat = ">q";
					this.esfImportFieldSeparator = '>'.ToString();
					this.esfImportFormatTitle = "[>";
				}
				text = gf.Right(text, text.Length - 8);
				text = text.Replace(this.esfImportFormatTitle, Convert.ToString('\u0001'));
				this.Cursor = Cursors.WaitCursor;
				int folderNumber = gf.GetFolderNumber(this.SongFolder.SelectedItems[0].Text);
				ListViewItem listViewItem = new ListViewItem();
				string[] array = text.Split(new char[]
				{
					'\u0001'
				});
				string text2 = "";
				for (int i = 0; i < this.ImportFolderList.CheckedItems.Count; i++)
				{
					text2 = text2 + this.ImportFolderList.CheckedItems[i].ToString() + ";";
				}
				Database daoDb = gf.GetDaoDb(gf.ConnectStringMainDB);
				this.ProgressBar1.Visible = true;
				listViewItem = this.SongsList.Items.Add("");
				listViewItem.SubItems.Add("Starting Import...");
				if (array != null && array.GetUpperBound(0) >= 0)
				{
					int num = 0;
					int num2 = 0;
					this.SongsUpdated = 0;
					this.SongsNew = 0;
					for (int i = 0; i <= array.GetUpperBound(0); i++)
					{
						int num3 = array[i].IndexOf("]");
						string text3 = gf.Left(array[i], (num3 > 0) ? num3 : 0);
						if (this.FolderLookupSongsCount < 1)
						{
							this.FolderLookupSongsCount = 1;
						}
						if (text3.Length > 0)
						{
							int num4 = text3.IndexOf(this.esfSongFolder);
							string str;
							if (num4 >= 0 & text3.Length > num4)
							{
								int num5 = text3.IndexOf(this.esfImportFieldSeparator, num4 + 1);
								if (num5 > 0)
								{
									str = gf.Mid(text3, num4 + this.esfSongFolder.Length, num5 - (num4 + this.esfSongFolder.Length));
								}
								else
								{
									str = gf.Mid(text3, num4 + this.esfSongFolder.Length);
								}
							}
							else
							{
								str = "Default Folder";
							}
							num++;
							int num6 = num * 100 / this.FolderLookupSongsCount;
							this.ProgressBar1.Value = ((num6 > 100) ? 100 : num6);
							base.Invalidate();
							this.ProgressBar1.Invalidate();
							if (text2.IndexOf(str + ";") >= 0)
							{
								gf.InitialiseIndividualData(ref this.ImportItem);
								this.LoadTextFileHeaderToItem(ref this.ImportItem, text3);
								string text4 = gf.Mid(array[i], (num3 + 1 < array[i].Length) ? (num3 + 1) : 0);
								if (text4.IndexOf("[~") >= 0)
								{
									int num7 = text4.IndexOf("[~") + "[~".Length;
									int num8 = text4.IndexOf("]", num7);
									if (num8 > num7)
									{
										this.ImportItem.Notations = gf.Mid(text4, num7, num8 - num7);
										text4 = gf.Mid(text4, num8 + 3);
									}
									else
									{
										text4 = "";
									}
								}
								text4 = text4.TrimStart(new char[]
								{
									'\n',
									'\r'
								});
								num2++;
								listViewItem = this.SongsList.Items.Add(num2.ToString());
								listViewItem.SubItems.Add(this.ImportItem.Title);
								string fullSearchString = string.Concat(new string[]
								{
									"select * from SONG where Folderno=",
									Convert.ToString(folderNumber),
									" and Title_1 = \"",
									this.ImportItem.Title,
									"\""
								});
								bool flag = true;
								Recordset recordSet = gf.GetRecordSet(daoDb, fullSearchString);
								if (recordSet != null && !recordSet.EOF)
								{
									recordSet.MoveFirst();
									this.CurSongID = gf.GetDataInt(recordSet, "SongID");
									if (this.OptImport0.Checked)
									{
										flag = false;
									}
									else
									{
										if (this.OptImport1.Checked)
										{
											this.CurSongID = -1;
										}
									}
								}
								else
								{
									this.CurSongID = -1;
								}
								if (recordSet != null)
								{
									recordSet.Close();
								}
								if (flag)
								{
									if (this.ImportItem.Title != "")
									{
										this.ImportItem.CompleteLyrics = text4.Replace("\r\n", "\n");
										this.ImportItem.FolderNo = folderNumber;
										this.SaveSong(flag, this.CurSongID, this.ImportItem, ref listViewItem, ref this.SongsNew, ref this.SongsUpdated);
									}
									else
									{
										listViewItem.SubItems.Add("Item has No Title - Not Imported");
									}
								}
								else
								{
									listViewItem.SubItems.Add("Song exists in Database - NOT Imported");
								}
							}
						}
						this.SongsList.Items[this.SongsList.Items.Count - 1].EnsureVisible();
						this.SongsList.Update();
					}
				}
				this.ProgressBar1.Value = 100;
				this.Cursor = Cursors.Default;
				this.Show_Import_Result();
				return;
			}
			IL_7C3:
			MessageBox.Show("There was an error reading the Import File - the file might not be a valid EasiSlides File");
			this.ProgressBar1.Visible = false;
		}
		private void LoadTextFileHeaderToItem(ref gf.SongSettings InItem, string InString)
		{
			int num = InString.IndexOf(this.esfImportFieldSeparator);
			if (num > 0)
			{
				InItem.Title = gf.Left(InString, num);
				InString = gf.Mid(InString, num + 1);
				while (InString.Length > 0)
				{
					num = InString.IndexOf(this.esfImportFieldSeparator, 1);
					string text;
					if (num > 0)
					{
						text = gf.Left(InString, num);
						InString = gf.Mid(InString, num + 1);
					}
					else
					{
						text = InString;
						InString = "";
					}
					string a;
					if (text.Length > 2)
					{
						a = this.esfImportFieldSeparator + text[0].ToString();
						text = gf.Mid(text, 1);
					}
					else
					{
						a = "";
						text = "";
					}
					if (a != "")
					{
						if (a == this.esfSongTitle2)
						{
							InItem.Title2 = text;
						}
						else
						{
							if (a == this.esfSongFolder)
							{
								InItem.FolderName = text;
							}
							else
							{
								if (a == this.esfSongNumber)
								{
									InItem.SongNumber = gf.StringToInt(text);
								}
								else
								{
									if (a == this.esfBookReference)
									{
										InItem.Book_Reference = text;
									}
									else
									{
										if (a == this.esfUserReference)
										{
											InItem.User_Reference = text;
										}
										else
										{
											if (a == this.esfSongCopyright)
											{
												InItem.Copyright = text;
											}
											else
											{
												if (a == this.esfSongWriterInfo)
												{
													InItem.Writer = text;
												}
												else
												{
													if (a == this.esfSongKey)
													{
														InItem.MusicKey = text;
													}
													else
													{
														if (a == this.esfSongCapo)
														{
															InItem.Capo = gf.StringToInt(text);
														}
														else
														{
															if (a == this.esfSongTiming)
															{
																InItem.Timing = text;
															}
															else
															{
																if (a == this.esfSongAdmin1)
																{
																	InItem.Show_LicAdminInfo1 = text;
																}
																else
																{
																	if (a == this.esfSongAdmin2)
																	{
																		InItem.Show_LicAdminInfo2 = text;
																	}
																	else
																	{
																		if (a == this.esfSequence)
																		{
																			InItem.SongSequence = gf.ConvertTextStringToSequence(text);
																		}
																		else
																		{
																			if (a == this.esfSongFormat)
																			{
																				InItem.Format.FormatString = text;
																			}
																		}
																	}
																}
															}
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
		private void AccessHelper(string ImportFileName)
		{
			if (gf.Right(ImportFileName, 4) == ".mdb")
			{
				gf.Import_AccessFileName = ImportFileName;
				FrmImportAccessHelper frmImportAccessHelper = new FrmImportAccessHelper();
				if (frmImportAccessHelper.ShowDialog() == DialogResult.OK)
				{
					base.Update();
					this.Import_AccessDatabase(ImportFileName, true);
					base.Update();
				}
			}
		}
		private void Import_AccessDatabase(string ImportFileName, bool UsedHelper)
		{
			if (!UsedHelper)
			{
				gf.Import_SongTitleColumnName = "Title_1";
				gf.Import_SongTitle2ColumnName = "Title_2";
				gf.Import_SongNumberColumnName = "SONG_NUMBER";
				gf.Import_SongCopyrightColumnName = "copyright";
				gf.Import_BookReferenceColumnName = "BOOK_REFERENCE";
				gf.Import_UserReferenceColumnName = "USER_REFERENCE";
				gf.Import_SongWriterInfoColumnName = "writer";
				gf.Import_SongLyricsColumnName = "Lyrics";
				gf.Import_SongKeyColumnName = "key";
				gf.Import_SongTimingColumnName = "Timing";
				gf.Import_Admin1ColumnName = "LICENCE_ADMIN1";
				gf.Import_Admin2ColumnName = "LICENCE_ADMIN2";
			}
			this.sArray = gf.Import_SongLyricsColumnName.Split(new char[]
			{
				'>'
			});
			if (this.sArray != null)
			{
				for (int i = 0; i <= this.sArray.GetUpperBound(0); i++)
				{
					this.sArray[i] = gf.Trim(this.sArray[i]);
				}
			}
			int num = 0;
			ListViewItem listViewItem = new ListViewItem();
			this.SongsUpdated = 0;
			this.SongsNew = 0;
			this.Cursor = Cursors.WaitCursor;
			this.SongsList.Items.Clear();
			this.ProgressBar1.Visible = true;
			this.ProgressBar1.Value = 0;
			int num2 = 0;
			Recordset recordSet = gf.GetRecordSet(gf.ConnectStringDef + ImportFileName, "select * from " + gf.Import_TableName);
			if (recordSet != null && !recordSet.EOF)
			{
				recordSet.MoveFirst();
				while (!recordSet.EOF)
				{
					num2++;
					recordSet.MoveNext();
				}
				recordSet.MoveFirst();
				listViewItem = this.SongsList.Items.Add("Importing...");
				int folderNumber = gf.GetFolderNumber(this.SongFolder.SelectedItems[0].Text);
				Database daoDb = gf.GetDaoDb(gf.ConnectStringMainDB);
				Recordset recordset = null;
				while (!recordSet.EOF)
				{
					bool songRequired = false;
					num++;
					int num3 = num * 100 / num2;
					this.ProgressBar1.Value = ((num3 > 100) ? 100 : num3);
					base.Invalidate();
					this.ProgressBar1.Invalidate();
					if (this.LoadExternalAccessDatabaseToItem(ref this.ImportItem, recordSet))
					{
						listViewItem = this.SongsList.Items.Add(Convert.ToString(num));
						listViewItem.SubItems.Add(this.ImportItem.Title);
						string fullSearchString = string.Concat(new string[]
						{
							"select * from SONG where Folderno=",
							folderNumber.ToString(),
							" and Title_1 = \"",
							this.ImportItem.Title,
							"\""
						});
						songRequired = true;
						this.ImportItem.FolderNo = folderNumber;
						recordset = gf.GetRecordSet(daoDb, fullSearchString);
					}
					if (recordset != null && !recordset.EOF)
					{
						recordset.MoveFirst();
						this.CurSongID = gf.GetDataInt(recordset, "SongID");
						if (this.OptImport0.Checked)
						{
							songRequired = false;
						}
						else
						{
							if (this.OptImport1.Checked)
							{
								this.CurSongID = -1;
							}
						}
					}
					else
					{
						this.CurSongID = -1;
					}
					if (recordset != null)
					{
						recordset.Close();
					}
					this.SaveSong(songRequired, this.CurSongID, this.ImportItem, ref listViewItem, ref this.SongsNew, ref this.SongsUpdated);
					recordSet.MoveNext();
					this.SongsList.Items[this.SongsList.Items.Count - 1].EnsureVisible();
					this.SongsList.Update();
				}
				recordSet.Close();
				this.ProgressBar1.Value = 100;
				this.Show_Import_Result();
				if (recordset != null)
				{
				}
				if (recordSet != null)
				{
				}
				this.Cursor = Cursors.Default;
			}
		}
		private bool LoadExternalAccessDatabaseToItem(ref gf.SongSettings InItem, Recordset rsIm)
		{
			bool result;
			try
			{
				InItem.Title = gf.GetDataString(rsIm, gf.Import_SongTitleColumnName);
				InItem.Title2 = gf.GetDataString(rsIm, gf.Import_SongTitle2ColumnName);
				InItem.SongNumber = gf.GetDataInt(rsIm, gf.Import_SongNumberColumnName);
				InItem.CompleteLyrics = this.GetMergedSongLyrics(rsIm);
				InItem.Copyright = gf.GetDataString(rsIm, gf.Import_SongCopyrightColumnName);
				InItem.Show_LicAdminInfo1 = gf.GetDataString(rsIm, gf.Import_Admin1ColumnName);
				InItem.Show_LicAdminInfo2 = gf.GetDataString(rsIm, gf.Import_Admin2ColumnName);
				InItem.Notations = gf.GetDataString(rsIm, "msc");
				InItem.Capo = gf.GetDataInt(rsIm, "capo", true);
				InItem.SongSequence = gf.GetDataString(rsIm, "Sequence");
				InItem.Writer = gf.GetDataString(rsIm, gf.Import_SongWriterInfoColumnName);
				InItem.Book_Reference = gf.GetDataString(rsIm, gf.Import_BookReferenceColumnName);
				InItem.User_Reference = gf.GetDataString(rsIm, gf.Import_UserReferenceColumnName);
				InItem.Timing = gf.GetDataString(rsIm, gf.Import_SongTimingColumnName);
				InItem.MusicKey = gf.GetDataString(rsIm, gf.Import_SongKeyColumnName);
				InItem.Format.FormatString = "";
				result = true;
			}
			catch
			{
				result = false;
			}
			return result;
		}
		private string GetMergedSongLyrics(Recordset rs)
		{
			string text = "";
			if (this.sArray != null)
			{
				for (int i = 0; i <= this.sArray.GetUpperBound(0); i++)
				{
					string text2 = gf.TrimEnd(Convert.ToString(gf.GetDataString(rs, this.sArray[i])));
					if (text2 != "")
					{
						text = text + text2 + "\n\n";
					}
				}
			}
			return gf.TrimEnd(text);
		}
		private void BtnImportHelper_Click(object sender, EventArgs e)
		{
			if (gf.Trim(this.tbImportFrom.Text) == "")
			{
				MessageBox.Show("Cannot start Helper - Please specify an Access Database file.");
			}
			else
			{
				if (this.SongFolder.SelectedItems.Count < 1)
				{
					MessageBox.Show("Cannot start Helper - Please select a Song Folder to Import Access database items into.");
				}
				else
				{
					string text = gf.Trim(this.tbImportFrom.Text);
					if (!File.Exists(text))
					{
						MessageBox.Show("Cannot start Helper - The Access Database file specified does not exist - please select a valid import file!");
					}
					else
					{
						if (gf.Right(text, 4) == ".mdb")
						{
							gf.Import_AccessFileName = text;
							FrmImportAccessHelper frmImportAccessHelper = new FrmImportAccessHelper();
							if (frmImportAccessHelper.ShowDialog() == DialogResult.OK)
							{
								this.Import_AccessDatabase(text, true);
								base.Update();
							}
						}
						else
						{
							MessageBox.Show("Cannot start Helper - The specified file is not an Access Database file");
						}
					}
				}
			}
		}
		private void FrmImport_KeyUp(object sender, KeyEventArgs e)
		{
			if (e.Control && e.KeyCode == Keys.T)
			{
				this.DoSourceCDExtract();
			}
		}
		private void DoSourceCDExtract()
		{
			if (this.SongFolder.SelectedItems.Count < 1)
			{
				MessageBox.Show("Please select a Folder to Import the Source materials into (C).");
			}
			else
			{
				string text = "D:\\Source CD\\hymns";
				if (!Directory.Exists(text))
				{
					MessageBox.Show("The source CD Folder '" + text + "' does not exists!");
				}
				else
				{
					string[] array = new string[2600];
					if (this.DoSourceCDIndexExtract(ref array))
					{
						Database daoDb = gf.GetDaoDb(gf.ConnectStringMainDB);
						Recordset recordset = null;
						try
						{
							ListViewItem listViewItem = new ListViewItem();
							listViewItem = this.SongsList.Items.Add("Importing...");
							int num = 0;
							this.SongsNew = 0;
							this.SongsUpdated = 0;
							string[] files = Directory.GetFiles(text, "*.html");
							int num2 = files.GetUpperBound(0) + 1;
							this.ProgressBar1.Visible = true;
							this.ProgressBar1.Value = 0;
							string text2 = "";
							int folderNumber = gf.GetFolderNumber(this.SongFolder.SelectedItems[0].Text);
							string[] array2 = files;
							for (int i = 0; i < array2.Length; i++)
							{
								string importFileName = array2[i];
								num++;
								int num3 = num * 100 / num2;
								this.ProgressBar1.Value = ((num3 > 100) ? 100 : num3);
								base.Invalidate();
								this.ProgressBar1.Invalidate();
								this.ExtractOneSourceCDHTMLIntoItem(ref this.ImportItem, importFileName, ref array);
								listViewItem = this.SongsList.Items.Add(num.ToString());
								listViewItem.SubItems.Add(this.ImportItem.Title);
								string fullSearchString = string.Concat(new string[]
								{
									"select * from SONG where Folderno=",
									Convert.ToString(folderNumber),
									" and Title_1 = \"",
									this.ImportItem.Title,
									"\""
								});
								bool flag = true;
								recordset = gf.GetRecordSet(daoDb, fullSearchString);
								if (recordset != null && !recordset.EOF)
								{
									recordset.MoveFirst();
									this.CurSongID = gf.GetDataInt(recordset, "SongID");
									if (this.OptImport0.Checked)
									{
										flag = false;
									}
									else
									{
										if (this.OptImport1.Checked)
										{
											this.CurSongID = -1;
										}
									}
								}
								else
								{
									this.CurSongID = -1;
								}
								if (recordset != null)
								{
									recordset.Close();
								}
								if (flag)
								{
									if (this.ImportItem.Title != "")
									{
										this.ImportItem.FolderNo = folderNumber;
										string fullSearchString2 = "select * from SONG where Folderno > 0 and UCase(book_reference) like \"*" + this.ImportItem.Book_Reference + "*\"";
										recordset = gf.GetRecordSet(daoDb, fullSearchString2);
										if (recordset != null && !recordset.EOF)
										{
											recordset.MoveFirst();
											bool flag2 = false;
											while (!recordset.EOF && !flag2)
											{
												string dataString = gf.GetDataString(recordset, "book_reference");
												text2 = dataString;
												while (text2.Length > 0 && !flag2)
												{
													if (gf.ExtractOneInfo(ref text2, ',').ToUpper().TrimStart(new char[]
													{
														' '
													}) == this.ImportItem.Book_Reference)
													{
														this.ImportItem.Book_Reference = dataString;
														flag2 = true;
													}
												}
												recordset.MoveNext();
											}
										}
										this.SaveSong(flag, this.CurSongID, this.ImportItem, ref listViewItem, ref this.SongsNew, ref this.SongsUpdated);
									}
									else
									{
										listViewItem.SubItems.Add("Item has No Title - Not Imported");
									}
								}
								else
								{
									listViewItem.SubItems.Add("Song exists in Database - NOT Imported");
								}
								this.SongsList.Items[this.SongsList.Items.Count - 1].EnsureVisible();
								this.SongsList.Update();
							}
						}
						catch
						{
						}
						this.ProgressBar1.Value = 100;
						this.Cursor = Cursors.Default;
						this.Show_Import_Result();
						if (recordset != null)
						{
							recordset = null;
						}
					}
				}
			}
		}
		private bool DoSourceCDIndexExtract(ref string[] SourceCDSongTitle)
		{
			for (int i = 0; i < 2600; i++)
			{
				SourceCDSongTitle[i] = "";
			}
			string text = "D:\\Source CD\\hymnindex.htm";
			bool result;
			if (!File.Exists(text))
			{
				result = false;
			}
			else
			{
				string text2 = gf.LoadTextFile(text);
				text2 = text2.Replace("<tr>", Convert.ToString('\u0001'));
				string[] array = text2.Split(new char[]
				{
					'\u0001'
				});
				try
				{
					for (int i = 4; i <= 2532; i++)
					{
						array[i] = array[i].Replace('\n', ' ');
						if (array[i].IndexOf("<em>") < 0)
						{
							string text3 = this.ExtractOneHTMLStream(ref array[i]).Replace(",", "");
							string inString = this.ExtractOneHTMLStream(ref array[i]);
							if (text3.Length > 0 && gf.StringToInt(inString) > 0)
							{
								SourceCDSongTitle[gf.StringToInt(inString)] = text3;
							}
						}
					}
					result = true;
				}
				catch
				{
					result = false;
				}
			}
			return result;
		}
		private string ExtractOneHTMLStream(ref string InString)
		{
			int num = InString.IndexOf('>');
			int num2 = InString.IndexOf('<', num + 1);
			string result;
			while (num >= 0 & num2 >= 0 & num2 > num)
			{
				string text = gf.Trim(gf.Mid(InString, num + 1, num2 - (num + 1)));
				if (text.Length > 0)
				{
					InString = gf.Mid(InString, num2 + 1);
					result = text;
					return result;
				}
				num = InString.IndexOf('>', num2);
				num2 = InString.IndexOf('<', (num >= 0) ? num : (InString.Length - 1));
			}
			InString = "";
			result = "";
			return result;
		}
		private void ExtractOneSourceCDHTMLIntoItem(ref gf.SongSettings InItem, string ImportFileName, ref string[] SourceCDSongTitle)
		{
			if (File.Exists(ImportFileName))
			{
				string text = gf.LoadTextFile(ImportFileName);
				int num = gf.StringToInt(gf.GetDisplayNameOnly(ref ImportFileName, false, false));
				text = text.Replace("InstanceBeginEditable name=", Convert.ToString('\u0001'));
				string[] array = text.Split(new char[]
				{
					'\u0001'
				});
				string[] array2 = new string[4];
				string value = "<!--";
				array2[0] = "\"content\" -->";
				array2[1] = "\"Author\" -->";
				array2[2] = "\"copyright\" -->";
				string[] array3 = new string[4];
				array3[0] = "";
				array3[1] = "";
				array3[2] = "";
				if (array != null && array.GetUpperBound(0) >= 0)
				{
					for (int i = 0; i <= array.GetUpperBound(0); i++)
					{
						for (int j = 0; j < 3; j++)
						{
							int num2 = array[i].IndexOf(array2[j]);
							if (num2 >= 0)
							{
								int num3 = array[i].IndexOf(value, num2 + array2[j].Length);
								num3 = ((num3 < num2 + array2[j].Length) ? array[i].Length : num3);
								array3[j] = gf.Mid(array[i], num2 + array2[j].Length, num3 - (num2 + array2[j].Length));
							}
						}
					}
				}
				gf.InitialiseIndividualData(ref this.ImportItem);
				if (num > 0)
				{
					InItem.Title = SourceCDSongTitle[num];
					if (InItem.Title != "")
					{
						InItem.Book_Reference = "TS" + num.ToString();
						InItem.SongSequence = this.ConvertHTMLLines(ref array3[0]);
						InItem.CompleteLyrics = array3[0];
						InItem.Writer = this.RemoveHTMLTags(array3[1].Trim());
						InItem.Copyright = this.RemoveHTMLTags(array3[2].Trim());
						if (InItem.Copyright.ToLower().IndexOf("public domain") >= 0 || InItem.Copyright.Length == 0)
						{
							InItem.Show_LicAdminInfo1 = "Public Domain";
						}
						else
						{
							InItem.Show_LicAdminInfo1 = "CCLI";
						}
					}
				}
			}
		}
		private string ConvertHTMLLines(ref string InContents)
		{
			InContents = InContents.Replace("\r", "");
			InContents = InContents.Replace("\n", "");
			InContents = InContents.Replace("<p>", "<br><br>");
			InContents = InContents.Replace("<br>", Convert.ToString('\u0001'));
			StringBuilder stringBuilder = new StringBuilder();
			string[] array = InContents.Split(new char[]
			{
				'\u0001'
			});
			bool flag = false;
			if (array != null && array.GetUpperBound(0) >= 0)
			{
				for (int i = 0; i <= array.GetUpperBound(0); i++)
				{
					if (array[i].IndexOf("<em>") >= 0 && !flag)
					{
						flag = true;
						stringBuilder.Append(gf.VerseSymbol[0] + "\n");
					}
					array[i] = this.RemoveHTMLTags(array[i]);
					bool flag2 = i < array.GetUpperBound(0) && array[i + 1].IndexOf("&nbsp;") >= 0;
					stringBuilder.Append(array[i] + (flag2 ? " " : "\n"));
				}
			}
			InContents = stringBuilder.ToString();
			return this.InsertVertIndicators(ref InContents);
		}
		private string InsertVertIndicators(ref string InString)
		{
			string text = InString;
			string text2 = "";
			text = text.TrimStart(new char[]
			{
				'\n',
				'\r'
			});
			text = text.TrimEnd(new char[]
			{
				'\n',
				'\r'
			});
			text = text.Replace("\n\n", Convert.ToString('\u0001'));
			string[] array = text.Split(new char[]
			{
				'\u0001'
			});
			string result;
			if (array != null && array.GetUpperBound(0) >= 0)
			{
				int num = (array[array.GetUpperBound(0)] != "") ? array.GetUpperBound(0) : (array.GetUpperBound(0) - 1);
				if (num > 0)
				{
					if (array[0].IndexOf(gf.VerseSymbol[0]) >= 0)
					{
						text2 += '\0';
						for (int i = 1; i <= num; i++)
						{
							text2 += (char)i;
							text2 += '\0';
							array[i] = gf.VerseSymbol[i] + "\n" + array[i].TrimStart(new char[]
							{
								'\n',
								'\r'
							});
						}
						if (num < 2)
						{
							text2 = "";
						}
					}
					else
					{
						if (array[1].IndexOf(gf.VerseSymbol[0]) >= 0 && num > 1)
						{
							text2 += '\u0001';
							text2 += '\0';
							array[0] = gf.VerseSymbol[1] + "\n" + array[0].TrimStart(new char[]
							{
								'\n',
								'\r'
							});
							for (int i = 2; i <= num; i++)
							{
								text2 += (char)i;
								text2 += '\0';
								array[i] = gf.VerseSymbol[i] + "\n" + array[i].TrimStart(new char[]
								{
									'\n',
									'\r'
								});
							}
						}
						else
						{
							if (text.IndexOf(gf.VerseSymbol[0]) < 0)
							{
								for (int i = 0; i <= num; i++)
								{
									array[i] = gf.VerseSymbol[i + 1] + "\n" + array[i].TrimStart(new char[]
									{
										'\n',
										'\r'
									});
								}
							}
						}
					}
					InString = "";
					for (int i = 0; i <= num; i++)
					{
						InString = InString + array[i].TrimEnd(new char[]
						{
							'\n',
							'\r'
						}) + ((i < num) ? "\n" : "");
					}
					result = text2;
				}
				else
				{
					InString = array[0];
					result = "";
				}
			}
			else
			{
				result = "";
			}
			return result;
		}
		private string RemoveHTMLTags(string InContents)
		{
			string result;
			if (InContents.Length == 0)
			{
				result = "";
			}
			else
			{
				InContents = InContents.Replace("&nbsp;", "");
				string text = "";
				bool flag = false;
				bool flag2 = false;
				for (int i = 0; i < InContents.Length; i++)
				{
					if (InContents[i] == '<')
					{
						flag = true;
					}
					if (!flag)
					{
						if (!(InContents[i] == ' ' & flag2))
						{
							text += InContents[i].ToString();
						}
					}
					if (InContents[i] == '>')
					{
						flag = false;
					}
					flag2 = (InContents[i] == ' ');
				}
				result = text.Trim();
			}
			return result;
		}

        private void BtnCancel_Click(object sender, EventArgs e)
        {
            base.Close();
        }
	}
}
